/*
 *  Copyright (C) 2008      Tri Tech Information Systems Inc.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include "control.h"
#include "parser.h"
#include "lexer.h"

#include <boost/python.hpp>
using namespace boost::python;


struct _Parser :
    public Parser
{
    // TODO:  REALLY IMPORTANT!!
    // When this goes away, I think the AST goes away too, we need
    // to figure a way to join the lifetimes...
    pool m_mempool;

    _Parser( Control* c ) :
        Parser( c )
    {
    }

//    TranslationUnitAST* parseFile( const std::string& filename )
//    {
//        Preprocessor proc;
//        std::string out = proc.processFile( filename );
//
//        return Parser::parse( out.c_str(), out.size(), &m_mempool );
//    }

    TranslationUnitAST* parse( const char* contents )
    {
        // I doubt strlen is the most efficient way of doing this...
//        return Parser::parse( contents, strlen(contents), &m_mempool );

        // Just throw pool on the heap and forget about it for now
        return Parser::parse( contents, strlen(contents), new pool );
    }
};

void Wrap_Parser()
{
    class_< Control, boost::noncopyable >( "Control" )
        ;

    class_< LocationManager, boost::noncopyable >( "LocationManager", no_init )
        ;

    class_< _Parser, boost::noncopyable >( "Parser", init<Control*>() )
        .def( "parse", &_Parser::parse, return_internal_reference<>() )
//        .def( "parseFile", _Parser::parse, return_internal_reference<>() )
        .def( "location", &_Parser::location, return_internal_reference<>() )
        ;
}
